home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / CDTools / GoFetch! / arexx / StandardScripts / browser.rexx next >
OS/2 REXX Batch file  |  1999-12-22  |  11KB  |  418 lines

  1. /*
  2. ** GoFetch ARexx Script
  3. ** Written By Marc Bradshaw
  4. ** for Zeus Developments
  5. **
  6.    v1.0 20.12.99 by Marc Bradshaw for Zeus Developments
  7. **
  8. ** Zeus WebSite    - http://www.bleach.demon.co.uk/zeus/
  9. ** GoFetch WebSite - http://www.bleach.demon.co.uk/zeus/
  10. ** Personal Sites  - http://www.bleach.demon.co.uk/
  11. **                   http://www.bleach.demon.co.uk/cramus/
  12. ** Zeus E-Mail     - zeus@bleach.demon.co.uk
  13. ** Personal E-Mail - dBnY@bleach.demon.co.uk
  14. */
  15.  
  16. /*
  17. ** Arguments are...    (see documentation for more in-depth descriptions)
  18. **
  19. ** URL <url> - The URL of the File to be Added to GoFetch's Profile List
  20. **
  21. ** AWEBSEL - in Which Case the Script will grab the URL from Selected Text in AWEB
  22. **           this should be used to integrate the script with the AWEB Browser
  23. **
  24. ** TO <download dir>
  25. **
  26. ** PATH <path to GoFetch!> - Where is the GoFetch! EXE Located?
  27. **
  28. ** NOREQ - Do NOT Use Requestors, for using browser.rexx in automatic scripts.
  29. **/
  30.  
  31. Options Results
  32.  
  33. IF ~SHOW('LIBRARIES','rexxsupport.library') THEN
  34.    Call ADDLIB('rexxsupport.library',10,-30,0)
  35.  
  36. Line=''
  37. CommandLine = Arg(1)
  38.  
  39. /*
  40. ** Setup Some Defaults
  41. **
  42. ** Please DONT Change These unless you Know What You Are Doing!
  43. ** The Script Gets ALL Info from the caller or from GoFetch
  44. ** You SHOULDNT NEED to alter ANY of these values.
  45. */
  46.  
  47. Debug       = 1 /* set to 1 when testing */
  48. Site        = ''
  49. Port        = 21
  50. HTTPPort    = 80
  51. LoginName   = 'anonymous'
  52. Password    = 'lazy.user@didnt.configure.com'
  53. RemotePath  = ''
  54. LocalPath   = ''
  55. FileName    = ''
  56. PortName    = 'GOFETCH'
  57. ExeName     = 'GoFetch!'
  58. TempFile    = 'T:GoFetch_Rexx'
  59. GoFetchPath = ''
  60. Requestors  = 1
  61. ReleaseNum  = 0
  62.  
  63. RequestChoicePath = WhereExe('RequestChoice')
  64.  
  65. /* Parse Command Line Arguments */
  66.  
  67. If CommandLine = '' Then CommandLine = '?'
  68. Parse Var CommandLine CommandArg CommandLine
  69.  
  70. Do While(CommandArg~="")
  71.  
  72.     /* Does User Want Help */
  73.     If CommandArg = '?' Then Do
  74.         Call Output('')
  75.         Call Output('GoFetch! browser.rexx Help')
  76.         Call Output('')
  77.         Call Output(Strip(SourceLine(6)))
  78.         Call Output('')
  79.         Call Output('rx browser.rexx [AWEBSEL | URL <url>] [TO <directory>] [PATH <path>] [?]')
  80.         Call Output('')
  81.         Call Output('')
  82.         Call Output('? - Request This Help Text')
  83.         Call Output('')
  84.         Call Output('AWEBSEL - if run from aweb, grabs selected text as url')
  85.         Call Output('          should not be used with the URL keyword')
  86.         Call Output('')
  87.         Call Output('URL <url> - the url to add as a profile')
  88.         Call Output('            should not be used with the AWEBSEL keyword')
  89.         Call Output('')
  90.         Call Output('TO <directory> - direcroty to download to')
  91.         Call Output('                 if not supplied the default as defined in')
  92.         Call Output('                 GoFetch! will be used.')
  93.         Call Output('')
  94.         Call Output('PATH <path> - GoFetch! Path The Path to the GoFetch! executable')
  95.         Call Output('              if not supplied the script will search the current')
  96.         Call Output('              command path for GoFetch!')
  97.         Call Output('')
  98.         Call Output('NOREQ - Do NOT Use Requestors, (Answer YES to all things)')
  99.         Call Output('        for using browser.rexx in automatic scripts.')
  100.         Call Output('')
  101.         EXIT
  102.     End
  103.  
  104.     /* Is It An AWeb Selection Text */
  105.     Else If Upper(CommandArg) = 'AWEBSEL' Then Do
  106.         Ports = SHOW('P')
  107.         PARSE VAR ports dummy 'AWEB.' portnr .
  108.         ADDRESS VALUE 'AWEB.' || portnr
  109.         'GET ACTIVEPORT'
  110.         ADDRESS VALUE RESULT
  111.         Address aweb.1
  112.         'get selection'
  113.         Line=RESULT
  114.     End
  115.  
  116.     /* Is It A URL */
  117.     Else If Upper(CommandArg) = 'URL' Then Do
  118.         Parse Var CommandLine Line CommandLine
  119.     End
  120.  
  121.     /* Is It A Download Directory */
  122.     Else If Upper(CommandArg) = 'TO' Then Do
  123.         Parse Var CommandLine LocalPath CommandLine
  124.     End
  125.  
  126.     /* Is It the Path to GoFetch! */
  127.     Else If Upper(CommandArg) = 'PATH' Then Do
  128.         Parse Var CommandLine GoFetchPath CommandLine
  129.     End
  130.  
  131.     /* Is It A NOREQ */
  132.     Else If Upper(CommandArg) = 'NOREQ' Then Do
  133.         Requestors = 0
  134.     End
  135.  
  136.     /* Must Be The Legacy URL */
  137.     Else Do
  138.         Line=CommandArg
  139.     End
  140.  
  141.     Parse Var CommandLine CommandArg CommandLine
  142.  
  143. End
  144.  
  145. /* If NoREQ Then NEVER Use RequestChoice */
  146. If Requestors=0 Then Do
  147.     RequestChoicePath = ''
  148. End
  149.  
  150. /* Remove Surrounding Quotes */
  151. If Left(Line,1)='"' Then
  152.     If Right(Line,1)='"' Then
  153.         Line=SubStr(Line,2,Length(Line)-2)
  154.  
  155. /* First We Check That GoFetch is Running */
  156. If ~Show('P',PortName) Then Do
  157.     /* It Isnt Running, Can We Find It In The Path? */
  158.     If ~Exists(GoFetchPath) Then Do
  159.         Call Alert('The Path to GoFetch! Is Incorrect.',1,'OK','',0)
  160.         GoFetchPath = ''
  161.     End
  162.     If GoFetchPath = '' Then Do
  163.         GoFetchPath = WhereExe(ExeName)
  164.     End
  165.     If GoFetchPath='' Then Do
  166.         Call Alert('GoFetch! is Not Running, and Cannot Be Located. Please Load GoFetch! and Try Again',1,'OK','',1)
  167.         EXIT 2
  168.     End
  169.     Else Do
  170.         /* We Found It, Do We Run It? */
  171.         Ret =  Alert('GoFetch! is Not Running, Run it Now?',2,'YES','NO',1)
  172.  
  173.         If Ret='1' Then Do
  174.             Call RunGoFetch
  175.         End
  176.         Else Do
  177.             Call Alert('GoFetch! Is Not Running, Please Try Again Later',1,'OK','',0)
  178.             EXIT 3
  179.         End
  180.     End
  181. End
  182.  
  183.  
  184. /* OK, GoFetch is Running, Lets Get Some Defaults From It */
  185.  
  186. Interpret 'Address 'PortName' release'
  187. ReleaseNum = RC
  188.  
  189. Interpret 'Address 'PortName' getanon'
  190. If RC=0 Then Password = RESULT
  191.  
  192. If LocalPath = '' Then Do
  193.     Interpret 'Address 'PortName' getdownloadpath'
  194.     If RC=0 Then LocalPath = RESULT
  195. End
  196.  
  197.  
  198. /* Parse the FTP URL to get the needed info */
  199.  
  200. /* Is it an FTP? */
  201. If Upper(Left(Line,6))='FTP://' Then Do
  202.     Type = 'FTP'
  203.     Line=Right(Line,Length(Line)-6)
  204. End
  205.  
  206. /* Is it an HTTP? */
  207. If Upper(Left(Line,7))='HTTP://' Then Do
  208.     Interpret 'Address 'PortName' registered'
  209.     If RC=0 Then Do
  210.         Call Alert('Sorry!  Downloads of type HTTP:// require a Registered version of GoFetch!',1,'OK','',0)
  211.         EXIT 4
  212.     End
  213.     If ReleaseNum<4 Then Do
  214.         Call Alert('Sorry!  Downloads of type HTTP:// are not supported in your version of GoFetch!',1,'OK','',0)
  215.         EXIT 4
  216.     End
  217.     Type='HTTP'
  218.     Line=Right(Line,Length(Line)-7)
  219.     Port=HTTPPort
  220.  
  221. End
  222.  
  223. /* Is it an FILE? */
  224. If Upper(Left(Line,7))='FILE://' Then Do
  225.     Call Alert('Sorry!  Downloads of type FILE:// are not supported.',1,'OK','',0)
  226.     EXIT 4
  227. End
  228.  
  229. /* No Type Indicated */
  230. If Type='' Then Do
  231.     Call Alert('Sorry!  Unknown Download Type.',1,'OK','',0)
  232.     EXIT 4
  233. End
  234.  
  235. /* Is URL Invalid? */
  236.  
  237. /* More Checking could be Included Here if thought necessary. */
  238.  
  239. If Index(Line,'/') = 0 Then Do
  240.     Call Alert('Invalid URL, Please Check and Try Again.',1,'OK','',0)
  241.     EXIT 5
  242. End
  243.  
  244. If Index(Line,'@')~=0 Then
  245.     Parse Var Line LoginName ':' Password '@' Site '/' FilePath
  246. Else
  247.     Parse Var Line Site '/' FilePath
  248.  
  249. FilePath = '/'FilePath
  250. FileBreak = LastPos('/',FilePath)
  251. RemotePath = Left(FilePath,FileBreak)
  252. FileName   = Right(FilePath,Length(FilePath)-FileBreak)
  253.  
  254. If Index(Site,':')~=0 Then
  255.     Parse Var Site Site ':' Port
  256.  
  257. If Debug Then Do
  258.     Say 'Profile Type : 'Type
  259.     Say 'Login Name   : 'LoginName
  260.     Say 'Password     : 'Password
  261.     Say 'Site Name    : 'Site
  262.     Say 'Port         : 'Port
  263.     Say 'Remote Pat h : 'RemotePath
  264.     Say 'File Name    : 'FileName
  265. End
  266.  
  267.  
  268. If Type='FTP' Then Do
  269.     Interpret 'Address 'PortName' '"'addprofile 'Site' 'Port' 'LoginName' 'Password' 'RemotePath' 'FileName' 'LocalPath''"''
  270.     RetCode = RC
  271. End
  272. Else If Type='HTTP' Then Do
  273.     URL = Site''RemotePath''Filename
  274.     Interpret 'Address 'PortName' '"'addhttpprofile 'URL' 'Port' 'LocalPath''"''
  275.     RetCode = RC
  276. End
  277.  
  278. If RetCode~=0 Then Do
  279.     Error = 'Undefined Internal Error, Type 'RetCode'  Please Report to Authors.'
  280.     If RetCode = -5 then
  281.         Error = 'You Must Register Go Fetch! To Use This Feature.'
  282.     If RetCode = -4 then
  283.         Error = 'Internal Error. Wrong Number of Parameters.  Please Report to Authors.'
  284.     If RetCode = -3 then
  285.         Error = 'Internal Error. Parameter of Wrong Type.  Please Report to Authors.'
  286.  
  287.     Call Alert(Error,1,'OK','',0)
  288.     EXIT RetCode
  289. End
  290.  
  291.  
  292. /*
  293. ** Start Download Right Now?
  294. */
  295.  
  296. If ReleaseNum>3 Then Do
  297.     Interpret 'Address 'PortName' dlstatus'
  298.     DLStatus = RC
  299. End
  300. Else
  301.     DLStatus=0
  302.  
  303. If DLStatus < 2 Then Do
  304.  
  305.     Ret=Alert('Start Download Right Now?',2,'Yes','No',1)
  306.     If Ret='1' Then Do
  307.         Call Output('Starting Download.')
  308.         Interpret 'Address 'Portname' gofetch'
  309.     End
  310.  
  311. End
  312.  
  313. Return = 0
  314. EXIT Return
  315.  
  316.  
  317.  
  318.  
  319.  
  320. Output:
  321.     Output_Line=Arg(1)
  322.     Say Output_Line
  323.     If Show('P',PortName) Then
  324.         If ReleaseNum>3 Then
  325.             Interpret "Address "PortName" annotate '"""Output_Line"""'"
  326. Return
  327.  
  328.  
  329.  
  330.  
  331.  
  332. Alert:
  333.     Alert_Title=Arg(1)
  334.     Alert_NumArgs=Arg(2)
  335.     Alert_First=Arg(3)
  336.     Alert_Second=Arg(4)
  337.     Alert_Default=Arg(5)
  338.  
  339.     Alert_Ret=Alert_Default
  340.  
  341.     Call Output(Alert_Title)
  342.     If RequestChoicePath ~= '' Then Do
  343.         If Alert_NumArgs=1 Then
  344.             CommandLine = RequestChoicePath" "'"GoFetch"'" "'"'Alert_Title'"'" "'"'Alert_First'"'" >"TempFile
  345.         Else
  346.             CommandLine = RequestChoicePath" "'"GoFetch"'" "'"'Alert_Title'"'" "'"'Alert_First'|'Alert_Second'"'" >"TempFile
  347.         Address Command CommandLine
  348.         Call Open(Alert_InF,TempFile,'R')
  349.         Alert_Ret=ReadLn(Alert_InF)
  350.         Call Close(Alert_InF)
  351.         Call DeleteFile(TempFile)
  352.     End
  353.  
  354. Return Alert_Ret
  355.  
  356.  
  357.  
  358.  
  359.  
  360. WhereExe: PROCEDURE Expose TempFile
  361. /*
  362. ** Locate A Particular Exe File
  363. ** Return The Full Path If Found
  364. ** Or Null String If Not Located.
  365. */
  366.     ExeName = Arg(1)
  367.     Options Failat 11
  368.     Address Command
  369.     'Which 'ExeName' >'TempFile
  370.     Ret=RC
  371.     Address
  372.     If Ret=0 Then Do
  373.         Call Open(InF,TempFile,'R')
  374.         ReturnPath=ReadLn(InF)
  375.         Call Close(InF)
  376.         Call DeleteFile(TempFile)
  377.     End
  378.     Else Do
  379.         ReturnPath = ''
  380.     End
  381. Return ReturnPath
  382.  
  383.  
  384.  
  385. RunGoFetch: PROCEDURE Expose GoFetchPath PortName RequestChoicePath
  386. /*
  387. ** Runs GoFetch
  388. */
  389.     /* Run GoFetch */
  390.     Address Command 'RUN <>NIL: 'GoFetchPath
  391.     /* Wait For Port */
  392.     Do I=1 to 15
  393.         Call Delay(100)
  394.         If Show('P',PortName) Then Return
  395.         Say 'Waiting...'
  396.     End
  397.     Call Alert('GoFetch! Could Not Be Started, Please Investigate and Try Again.',1,'OK','',0)
  398.     EXIT 1
  399. Return
  400.  
  401.  
  402.  
  403. DeleteFile: PROCEDURE
  404. /*
  405. ** Deletes a File
  406. */
  407.     FileName=Arg(1)
  408.  
  409.     IF SHOW('LIBRARIES','rexxsupport.library') THEN Do
  410.         Delete FileName
  411.     End
  412.  
  413. Return
  414.  
  415.  
  416. /* The End */
  417.  
  418.